package com.example.mylibrary;

import static android.content.ContentValues.TAG;
import android.app.Instrumentation;
import android.util.Log;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.uiautomator.By;
import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.UiObject2;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class InPage {
    public static Instrumentation instrumentation=null;
    public static UiDevice device=null;
    @Before
    public void initInstrumentation() throws InterruptedException {
        Log.i(TAG,"连接设备");
        instrumentation=
                InstrumentationRegistry.getInstrumentation();
        device=UiDevice.getInstance(instrumentation);
        device.pressHome();
        Thread.sleep(1000);
        UiObject2 icon1=device.findObject
                (By.text("CashBook"));
        icon1.click();
        Thread.sleep(3000);
    }

//    登录
    private void Login() throws InterruptedException {
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/et_account")).setText("Lizeyu");
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/et_psw")).setText("1");
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/login")).click();
    }

//   收入工资（计数器功能）
    @Test
    public void testInone() throws InterruptedException {

        Login();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/fb")).click();
        Thread.sleep(1000);
        device.findObject(By.clazz("androidx.appcompat.app.ActionBar$Tab")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/iv_gz")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/et_remark")).setText("三月份工资");
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_3")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_5")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_0")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_0")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_sure")).click();
        Thread.sleep(1000);
    }

    //   收入津贴（计数器功能）
    @Test
    public void testIntwo() throws InterruptedException {
        Login();
        device.findObject(By.res("com.lyc.cashbook:id/fb")).click();
        Thread.sleep(1000);
        device.findObject(By.clazz("androidx.appcompat.app.ActionBar$Tab")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/iv_jt")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_1")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_2")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_4")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_6")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_sure")).click();
        Thread.sleep(1000);
    }

    //   收入红包（计数器功能）
    @Test
    public void testInthree() throws InterruptedException {
        Login();
        device.findObject(By.res("com.lyc.cashbook:id/fb")).click();
        Thread.sleep(1000);
        device.findObject(By.clazz("androidx.appcompat.app.ActionBar$Tab")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/iv_hb")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_1")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_reset")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_2")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_4")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_6")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_dot")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_6")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_sure")).click();
        Thread.sleep(1000);
    }

    //   收入其他（计数器功能）
    @Test
    public void testInfour() throws InterruptedException {
        Login();
        device.findObject(By.res("com.lyc.cashbook:id/fb")).click();
        Thread.sleep(1000);
        device.findObject(By.clazz("androidx.appcompat.app.ActionBar$Tab")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/iv_qt")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/et_remark")).setText("生活用品费用");
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_9")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_delete")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_9")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_7")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_0")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_sure")).click();
        Thread.sleep(1000);
    }

    public void testInfive() throws InterruptedException {
        Login();
        device.findObject(By.res("com.lyc.cashbook:id/fb")).click();
        Thread.sleep(1000);
        device.findObject(By.clazz("androidx.appcompat.app.ActionBar$Tab")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/iv_qt")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_9")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_sure")).click();
        Thread.sleep(1000);
    }
    public void testInsix() throws InterruptedException {
        Login();
        device.findObject(By.res("com.lyc.cashbook:id/fb")).click();
        Thread.sleep(1000);
        device.findObject(By.clazz("androidx.appcompat.app.ActionBar$Tab")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/iv_hb")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_9")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_sure")).click();
        Thread.sleep(1000);
    }
    public void testInseven() throws InterruptedException {
        Login();
        device.findObject(By.res("com.lyc.cashbook:id/fb")).click();
        Thread.sleep(1000);
        device.findObject(By.clazz("androidx.appcompat.app.ActionBar$Tab")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/iv_gz")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_9")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_sure")).click();
        Thread.sleep(1000);
    }
    public void testIneight() throws InterruptedException {
        Login();
        device.findObject(By.res("com.lyc.cashbook:id/fb")).click();
        Thread.sleep(1000);
        device.findObject(By.clazz("androidx.appcompat.app.ActionBar$Tab")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/iv_jt")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_9")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.lyc.cashbook:id/btn_sure")).click();
        Thread.sleep(1000);
    }

//    查看图表数据
    @Test
    public void testTable() throws InterruptedException {
        Login();
        device.findObject(By.res("com.lyc.cashbook:id/tb")).click();
    }

    @Test
//添加多个大金额的收入，一个小金额的收入-查看图表
    public void testSix() throws InterruptedException {
        testInone();
        testIntwo();
        testInthree();
        testInfive();
        testTable();
    }

    @Test
//添加多个不同名不同价的收入账目-查看图表
    public void testSeven() throws InterruptedException {
        testInone();
        testIntwo();
        testInthree();
        testInfour();
        testTable();
    }

    @Test
//添加多个不同名同价的收入账目-查看图表
    public void testEight() throws InterruptedException {
        testInfive();
        testInsix();
        testInseven();
        testIneight();
        testTable();
    }

    @Test
//添加多个同名不同价的收入账目-查看图表
    public void testNine() throws InterruptedException {
        testIneight();
        testInone();
        testTable();
    }

    @Test
//添加多个同名同价的收入账目-查看图表
    public void testTen() throws InterruptedException {
        testInone();
        testInone();
        testInone();
        testTable();
    }




    @After
    public  void quite(){

        device.pressBack();
    }



}
